package com.student.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.student.dao.StudentDao;
import com.student.entity.PageTool;
import com.student.entity.StudentInfo;

public class queryStudentByPageservlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public queryStudentByPageservlet() {
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
			StudentDao studao = new StudentDao();
		request.setCharacterEncoding("utf-8");
//		int no = Integer.parseInt(request.getParameter("sno"));
		
		int totalCount = studao.getTotalCount();//总报名人数
		
		//将分页所需的5个变量(其中页数自动计算)组装到page 对象中
		PageTool page = new PageTool();
		page.setTotalCount(totalCount);
		
		int currentPage=1;
		int pageSize=5;
		
		page.setPageSize(pageSize);
		page.setCurrentPage(currentPage);
		
		List<StudentInfo> stuPage = studao.queryStudentByPage(currentPage-1, pageSize);
		page.setStuPage(stuPage);
		request.setAttribute("stuPage", page);
		

		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter out = response.getWriter();
		
		System.out.println("总数信息数："+totalCount+'\n');
		System.out.print("显示的5信息为："+stuPage);
		
	//	response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}


}
